package com.dayatang.hrm.compensation.domain;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.dayatang.commons.domain.InstanceFactory;
import com.dayatang.hrm.organisation.domain.Organization;
import com.dayatang.hrm.staffing.domain.Employee;

/**
 * 固定员工薪资参数记录
 * 
 * @author chencao
 * 
 */
@Entity
@Table(name = "pay_sp_record_fixed_emp")
public class FixedEmployeeSalaryParameterRecord extends SalaryParameterRecord {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1217459731757835261L;

	private static FixedEmployeeSalaryParameterRecordRepository fixedEmployeeSalaryParameterRecordRepository;

	// 固定员工薪资参数
	@ManyToOne
	@JoinColumn(name = "fixed_employee_sp_id")
	private FixedEmployeeSalaryParameter fixedEmployeeSalaryParameter;

	// 关联的员工
	@ManyToOne
	@JoinColumn(name = "employee_id")
	private Employee employee;

	public static FixedEmployeeSalaryParameterRecordRepository getFixedEmployeeSalaryParameterRecordRepository() {
		if (fixedEmployeeSalaryParameterRecordRepository == null) {
			fixedEmployeeSalaryParameterRecordRepository = InstanceFactory
					.getInstance(FixedEmployeeSalaryParameterRecordRepository.class);
		}
		return fixedEmployeeSalaryParameterRecordRepository;
	}

	public static void setFixedEmployeeSalaryParameterRecordRepository(
			FixedEmployeeSalaryParameterRecordRepository fixedEmployeeSalaryParameterRecordRepository) {
		FixedEmployeeSalaryParameterRecord.fixedEmployeeSalaryParameterRecordRepository = fixedEmployeeSalaryParameterRecordRepository;
	}

	public FixedEmployeeSalaryParameter getFixedEmployeeSalaryParameter() {
		return fixedEmployeeSalaryParameter;
	}

	public void setFixedEmployeeSalaryParameter(
			FixedEmployeeSalaryParameter fixedEmployeeSalaryParameter) {
		this.fixedEmployeeSalaryParameter = fixedEmployeeSalaryParameter;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	/*
	 * =======================================
	 * 
	 * action
	 * 
	 * ========================================
	 */

	public void save() {
		getFixedEmployeeSalaryParameterRecordRepository().save(this);
	}

	public static FixedEmployeeSalaryParameterRecord get(Long id) {
		return getFixedEmployeeSalaryParameterRecordRepository().get(id);
	}

	public static List<FixedEmployeeSalaryParameterRecord> findByOrganization(
			Organization org) {
		return getFixedEmployeeSalaryParameterRecordRepository()
				.findByOrganization(org);
	}

}
